From db4d5fc53b31b400a87951b434bcc5587b577ce7 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 8 Mar 2006 18:41:12 +0100 Subject: [PATCH] Allow pciback to be built as a module. From: Jan Beulich Signed-off-by: Keir Fraser --- linux-2.6-xen-sparse/drivers/xen/Kconfig | 6 ++-- .../drivers/xen/pciback/Makefile | 6 ++-- .../drivers/xen/pciback/conf_space_header.c | 8 ++--- .../drivers/xen/pciback/pci_stub.c | 34 +++++++++++++++++-- .../drivers/xen/pciback/pciback.h | 3 +- .../drivers/xen/pciback/pciback_ops.c | 13 +------ .../drivers/xen/pciback/xenbus.c | 5 +-- 7 files changed, 45 insertions(+), 30 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/Kconfig b/linux-2.6-xen-sparse/drivers/xen/Kconfig index 7a6a569a57..eaf774af55 100644 --- a/linux-2.6-xen-sparse/drivers/xen/Kconfig +++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig @@ -30,9 +30,9 @@ config XEN_UNPRIVILEGED_GUEST default !XEN_PRIVILEGED_GUEST config XEN_PCIDEV_BACKEND - bool "PCI device backend driver" - select PCI - default y if XEN_PRIVILEGED_GUEST + tristate "PCI device backend driver" + depends PCI + default XEN_PRIVILEGED_GUEST help The PCI device backend driver allows the kernel to export arbitrary PCI devices to other guests. diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile b/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile index e031caa03f..bfe77e64d7 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile @@ -1,9 +1,9 @@ -obj-y += pciback.o +obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pciback.o pciback-y := pci_stub.o pciback_ops.o xenbus.o pciback-y += conf_space.o conf_space_header.o -pciback-${CONFIG_XEN_PCIDEV_BACKEND_VPCI} += vpci.o -pciback-${CONFIG_XEN_PCIDEV_BACKEND_PASS} += passthrough.o +pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o +pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y) EXTRA_CFLAGS += -DDEBUG diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c b/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c index 17607d3bf4..0b9fce38bc 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c @@ -24,21 +24,19 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data) if (unlikely(verbose_request)) printk(KERN_DEBUG "pciback: %s: enable\n", pci_name(dev)); - dev->is_enabled = 1; - pcibios_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1); + pci_enable_device(dev); } else if (dev->is_enabled && !is_enable_cmd(value)) { if (unlikely(verbose_request)) printk(KERN_DEBUG "pciback: %s: disable\n", pci_name(dev)); - pciback_disable_device(dev); + pci_disable_device(dev); } if (!dev->is_busmaster && is_master_cmd(value)) { if (unlikely(verbose_request)) printk(KERN_DEBUG "pciback: %s: set bus master\n", pci_name(dev)); - dev->is_busmaster = 1; - pcibios_set_master(dev); + pci_set_master(dev); } if (value & PCI_COMMAND_INVALIDATE) { diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c b/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c index aa76d75d84..2e0b8a0110 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c @@ -208,8 +208,6 @@ static int __init pcistub_init_devices_late(void) return 0; } -device_initcall(pcistub_init_devices_late); - static int __devinit pcistub_seize(struct pci_dev *dev) { struct pci_stub_device *psdev; @@ -367,6 +365,7 @@ static int __init pcistub_init(void) return -EINVAL; } +#ifndef MODULE /* * fs_initcall happens before device_initcall * so pciback *should* get called first (b/c we @@ -375,3 +374,34 @@ static int __init pcistub_init(void) * driver to register) */ fs_initcall(pcistub_init); +#endif + +static int __init pciback_init(void) +{ +#ifndef MODULE + int err; + + err = pcistub_init(); + if (err < 0) + return err; +#endif + + if (list_empty(&pci_stub_device_ids)) + return -ENODEV; + pcistub_init_devices_late(); + pciback_xenbus_register(); + + __unsafe(THIS_MODULE); + + return 0; +} + +static void pciback_cleanup(void) +{ + BUG(); +} + +module_init(pciback_init); +module_exit(pciback_cleanup); + +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h index a1f408bf3a..f82ece4a2c 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h @@ -43,7 +43,6 @@ struct pci_dev *pcistub_get_pci_dev(struct pci_dev *dev); void pcistub_put_pci_dev(struct pci_dev *dev); /* Ensure a device is turned off or reset */ -void pciback_disable_device(struct pci_dev *dev); void pciback_reset_device(struct pci_dev *pdev); /* Access a virtual configuration space for a PCI device */ @@ -69,5 +68,7 @@ void pciback_release_devices(struct pciback_device *pdev); /* Handles events from front-end */ irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs); +int pciback_xenbus_register(void); + extern int verbose_request; #endif diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c index 9019608ab7..dcfd746a0f 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c @@ -10,17 +10,6 @@ int verbose_request = 0; module_param(verbose_request, int, 0644); -/* For those architectures without a pcibios_disable_device */ -void __attribute__ ((weak)) pcibios_disable_device(struct pci_dev *dev) { } - -void pciback_disable_device(struct pci_dev *dev) -{ - if (dev->is_enabled) { - dev->is_enabled = 0; - pcibios_disable_device(dev); - } -} - /* Ensure a device is "turned off" and ready to be exported. * This also sets up the device's private data to keep track of what should * be in the base address registers (BARs) so that we can keep the @@ -32,7 +21,7 @@ void pciback_reset_device(struct pci_dev *dev) /* Disable devices (but not bridges) */ if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) { - pciback_disable_device(dev); + pci_disable_device(dev); pci_write_config_word(dev, PCI_COMMAND, 0); diff --git a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c index b3dc7fb435..1df5feacdc 100644 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c @@ -430,10 +430,7 @@ static struct xenbus_driver xenbus_pciback_driver = { .otherend_changed = pciback_frontend_changed, }; -static __init int pciback_xenbus_register(void) +int __init pciback_xenbus_register(void) { return xenbus_register_backend(&xenbus_pciback_driver); } - -/* Must only initialize our xenbus driver after the pcistub driver */ -device_initcall(pciback_xenbus_register); -- 2.30.2